package cn.com.bluemoon.daps.sync.vo.syncmanage;

import cn.com.bluemoon.daps.common.domain.UserPermissionApi;
import cn.com.bluemoon.daps.common.enums.SyncToEnv;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.Optional;

/**
 * @author Jarod.Kong
 * @date 2021/7/20 10:52
 */
@ApiModel(description = "同步管理表级+环境入参")
@Data
public class SyncTableEnvParam implements UserPermissionApi<String> {
    @ApiModelProperty(value = "模型id", required = true)
    @NotNull(message = "模型id不可为空")
    private String modelId;

    @ApiModelProperty(value = "任务明细id", required = true)
    private String taskDetailId;

    @ApiModelProperty(value = "环境id, 3：预发布，4：生产", example = "3", required = true)
    @NotNull(message = "环境id不可为空")
    private Integer envCodeId;

    @ApiModelProperty(hidden = true)
    public Optional<SyncToEnv> syncToEnvOpt() {
        if (envCodeId == null) {
            return Optional.empty();
        }
        return Optional.ofNullable(SyncToEnv.valOf(envCodeId));
    }

    /**
     * @return 获取mvc传输中对应模型的id
     */
    @Override
    public String getUserPermissionKeyValue() {
        return getModelId();
    }
}
